<?php
/**
 * Created by PhpStorm.
 * User: zhangfulai
 * Date: 2018/10/3
 * Time: 下午5:30
 */
namespace app\obd\controller;
use think\Controller;
use app\obd\validate\Obdvalidate;
// use think\Db;
use app\obd\model\CarModel;
// use app\obd\model\Travel;
// use app\obd\model\Alarm;
class Cartype extends Controller{
    /**
     * 查询车辆品牌列表
     * @author 王涛
     * @DataTime 2018-08-11T19:45:41+0800
     * @return   [type]                   [description]
     */
    public function listCartype()
    {
        if(request()->isPost()){
            if(empty(input('listNum')))  return apiResponse(201,"listNum不能为空","");
            if(empty(input('pagenum')))  return apiResponse(201,"pagenum不能为空","");
            if(!empty(input('name'))) $w['NAME'] = array('like' , "%".input('name')."%" );
            $limit = input('listNum');
            $w['P_ID'] = 0;
            $w["CAR_STATUS"] = array("NEQ",9);
            $offset = (input('pagenum') - 1) * $limit;
            $carM = new CarModel(config('connection'));
            $data = $carM->cartypeList($w,$offset, $limit);
            $datas['list'] = $data;
            //查询数据总数
            $counts = $carM->cartypeCount($w);
            $datas['total'] = $counts;
            return apiResponse(200,"成功",$datas);
        }else{
            return apiResponse(201,"必须post请求","");
        }
    }
    /**
     * 查询车辆品牌详情
     * @author 王涛
     * @DataTime 2018-08-11T20:04:02+0800
     * @return   [type]                   [description]
     */
    public function infoCartype()
    {
        if(request()->isPost()){
            // var_dump(input('cartype_id'));die;
            if(empty(input('cartype_id')))  return apiResponse(201,"车辆品牌ID不能为空","");
            $Va = new Obdvalidate;
            $cartype_id = $Va->numbers(input('cartype_id'));
            if(empty($cartype_id)) return apiResponse(201,"输入的车辆品牌ID有误", '');

            $carM = new CarModel;
            $data = $carM->cartypeInfo(input('cartype_id'));
            if ($data) {
                return apiResponse(200,"成功",$data);
            }else{
                return apiResponse(201,"失败",'');
            }
        }else{
            return apiResponse(201,"必须post请求","");
        }
    }
    /**
     * 编辑车辆品牌
     * @author 王涛
     * @DataTime 2018-08-11T20:01:01+0800
     * @return   [type]                   [description]
     */
    public function editCartype()
    {
        if(request()->isPost()){
            if(empty(input('cartype_id')))  return apiResponse(201,"车辆品牌ID不能为空","");
            if(empty(input('logo_path')))  return apiResponse(201,"车辆品牌图片路径不能为空","");
            $Va = new Obdvalidate;
            $cartype_id = $Va->numbers(input('cartype_id'));
            if(empty($cartype_id)) return apiResponse(201,"输入的车辆品牌ID有误", '');

            $data['ID'] = input('cartype_id');
            $data['LOGO_PATH'] = input('logo_path');
            $data['MODIFY_TIME'] = date('Y-m-d H:i:s', time());

            $carM = new CarModel;
            $data = $carM->cartypeEdit($data);
            if ($data) {
                return apiResponse(200,"成功",'');
            }else{
                return apiResponse(201,"失败",'');
            }
        }else{
            return apiResponse(201,"必须post请求","");
        }
    }
}